package com.atguigu.tingshu.album.api;

import com.alibaba.fastjson.JSONObject;
import com.atguigu.tingshu.album.service.BaseCategoryService;
import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.model.album.BaseAttribute;
import com.atguigu.tingshu.model.album.BaseCategory1;
import com.atguigu.tingshu.model.album.BaseCategory3;
import com.atguigu.tingshu.model.album.BaseCategoryView;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.simpleframework.xml.Path;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;


@Tag(name = "分类管理")
@RestController
@RequestMapping(value="/api/album/category")
@SuppressWarnings({"all"})
public class BaseCategoryApiController {

	@Autowired
	private BaseCategoryService baseCategoryService;

	//分类接口:查询所有分类(三级分类)
	@Operation(summary = "查询所有分类")
	@GetMapping("/getBaseCategoryList")
	public Result getBaseCategoryList() {
//		List<Map> list = baseCategoryService.getBaseCategoryList();
		List<JSONObject> list = baseCategoryService.getBaseCategoryList();
		return Result.ok(list);
	}

	//接口:专辑标签
	@Operation(summary = "根据一级分类id查询分类属性数据")
	@GetMapping("/findAttribute/{id}")
	public Result<List<BaseAttribute>> findAttribute(@PathVariable Long id) {
		List<BaseAttribute> baseAttributeList = baseCategoryService.findAttribute(id);
		return Result.ok(baseAttributeList);
	}

	//远程调用接口：根据三级分类id获取分类所有数据
	@Operation(summary = "根据三级分类id获取分类所有数据")
	@GetMapping("/getCategoryView/{category3Id}")
	public Result getCategoryView(@PathVariable(value = "category3Id") Long category3Id) {
		BaseCategoryView baseCategoryView = baseCategoryService.getCatReegoryView(category3Id);
		return Result.ok(baseCategoryView);
	}

	//根据一级分类id获取三级分类数据
	@Operation(summary = "根据一级分类id获取三级分类数据")
	@GetMapping("/findTopBaseCategory3/{category1Id}")
	public Result<List<BaseCategory3>> getCategory3IdByCategory1Id(@PathVariable(value = "category1Id") Long category1Id) {
		List<BaseCategory3> category3List = baseCategoryService.getCategory3IdByCategory1Id(category1Id);
		return Result.ok(category3List);

	}

	//根据一级分类id获取全部数据
	@Operation(summary = "根据一级分类id获取全部数据")
	@GetMapping("/getBaseCategoryList/{category1Id}")
	public Result<JSONObject> getBaseCategoryList(@PathVariable(value = "category1Id") Long category1Id) {
		JSONObject jsonObject = baseCategoryService.getBaseCategoryList1(category1Id);
		return Result.ok(jsonObject);
	}
	//查询所有一级分类
	@Operation(summary = "查询所有一级分类")
	@GetMapping("/getCategory1")
	public Result<List<BaseCategory1>> getCategory1(){
	List<BaseCategory1> baseCategory1List = baseCategoryService.getCategory1();
	return Result.ok(baseCategory1List);
	}
}

